
$(function() {
	initData();
	initButton();
    
});


/**
 * 初始化数据
 */
function initData(){
	querylinkManGroup();//初始化查询列表
}

/**
 * 初始化按钮
 */
function initButton(){
	
	$(".press_btn2").click(function() {
		delGroup();
	});
	
	$(".press_btn1").click(function() {
		querylinkManGroup();
	});
	$('.addbtn').click(function(){
        layer.config({
            extend:['skin/layer_iframe.css'],
            skin:'layer-ext-skin-layer_iframe.css'
        });
        layer.open({
            type:2,
            title:'添加第三方联系人',
            area:['600px','400px'],

            content:basePath+'/radar/linkGroup/initaddlinkGroup.do',
            maxmin: true,
            shadeClose: true

        });
    });
}

function querylinkManGroup(){
	
	var  linkManGroupName=$("#linkManGroupName").val();//关联组名称

	var LinkGruop =[{code:'linkmansGroupId',name:'checkBox',width:10},
	           {code:'linkmansGroupName',name:'关联组名称'},
	           {code:'desc',name:'说明'},
	           {code:'remark',name:'备注'} ,       
	           {code : 'E_D_R_I',name : '操作'} ];	
	 var  parm={url:basePath+'/radar/linkGroup/getGroupList.do',divID:'linkGroup'};// 常规参数
	 var  data={GroupName:linkManGroupName};    // 赛选条件
     easyQuery(LinkGruop,parm,data);
}



function edit_linkGroup(thisObj){
	var $td = $(thisObj).parents('tr').children('td');
	var linkManGroupName = $td.eq(1).text();
	var desc = $td.eq(2).text();
	var remark = $td.eq(3).text();
	var linkmansGroupId = $(thisObj).parents('tr').attr('nodeId');
	layer.config({
        extend:['skin/layer_iframe.css'],
        skin:'layer-ext-skin-layer_iframe.css'
    });
    layer.open({
        type:2,
        title:'添加联系人分组',
        area:['600px','400px'],
        content:basePath+'/radar/linkGroup/initaddlinkGroup.do?linkManGroupName='+linkManGroupName+'&desc='+desc+'&remark='+remark+'&linkmansGroupId='+linkmansGroupId+'&editflag=0',
        maxmin: true,
        shadeClose: true

    });
}

/**操作 删除
 * @param f
 */
function del_linkGroup(f) {
	var id=$(f).parent().parent().attr("nodeId");	
	 dellinkManGroup(id);
	
}

/**关联按钮  关联联系人组
 * @param f
 */
function rela_linkGroup(f){
	var groupId=$(f).parent().parent().attr("nodeId");
    layer.config({
        extend:['skin/layer_iframe.css'],
        skin:'layer-ext-skin-layer_iframe.css'
    });
    layer.open({
        type:2,
        title:'关联联系人',
        area:['800px','400px'],

        content:basePath+'/radar/linkGroup/groupLinkMan.do?groupId='+groupId,
        maxmin: true,
        shadeClose: true
    });
}

function delGroup(){
	var id = '';
	$("input[type='checkbox'][nodeId][ divID='linkGroup']:checked").each(function() {
		id = id + $(this).attr("nodeId") + ",";
	});
	if (id == '') {
		layer.msg('请选择要删除的选项', {
			icon : 1
		});
		return;
	}
	id = id.substring(0, id.length - 1);
	dellinkManGroup(id);
}

/**删除方法
 * @param id
 */
function dellinkManGroup(id){
	var index = layer.confirm("确认删除？", {
		btn : [ '确定', '取消' ]
	// 按钮
	}, function() {
		$.ajax({
			url : basePath+"/radar/linkGroup/dellinkGroup.do",
			type : "POST",
			dataType:"json",
			data : {
				"id":id
			},
			success:function(data){
				if(data.errorMessage == ""){
					layer.msg('删除成功！', {icon : 1});
					reQuery('linkGroup');
				}else{
					layer.msg('删除失败！', {icon : 1});
					reQuery('linkGroup');
				}
			}
		});

});
}

function ser_linkGroup(f){
	var groupId=$(f).parent().parent().attr("nodeId");
    layer.config({
        extend:['skin/layer_iframe.css'],
        skin:'layer-ext-skin-layer_iframe.css'
    });
    layer.open({
        type:2,
        title:'关联资源列表',
        area:['800px','400px'],

        content:basePath+'/radar/linkGroup/groupResourceView.do?groupId='+groupId,
        maxmin: true,
        shadeClose: true
    });
}
